﻿using UnityEngine;
using strange.extensions.command.impl;
using strange.extensions.dispatcher.eventdispatcher.api;

public class UpdateScoreCommand : EventCommand 
{
	[Inject]
	public ScoreModel scoreModel{ get; set;}
	[Inject]
	public IScoreService scoreService{ get; set;}

	public override void Execute ()
	{
		Retain ();
		scoreModel.Score++;
		scoreService.dispachter.AddListener (ServiceEvent.UpdateScore, OnComplete);
		scoreService.UpdateScore ("", scoreModel.Score);
	}

	public void OnComplete(IEvent evt)
	{
		scoreService.dispachter.RemoveListener (ServiceEvent.UpdateScore, OnComplete);
		dispatcher.Dispatch (MediatorEvent.ScoreChange, (int)evt.data);

		Release ();
	}
}
